package com.denlaku.longan.event;

import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;

/**
 * 消息生产者类
 *
 * @author tianx
 */
public class MessageEventProducer {
    private final RingBuffer<MessageEvent> ringBuffer;

    public MessageEventProducer(RingBuffer<MessageEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    /**
     * 将接收到的消息输出到ringBuffer
     *
     * @param content 消息内容
     */
    public <T> void onData(T content) {
        EventTranslatorOneArg<MessageEvent, T> translator = new MessageEventTranslator<>();
        ringBuffer.publishEvent(translator, content);
    }
}